package helper.form.inputs;

public class CheckBoxInput extends BasicInput {

	protected boolean checked;	
	
	public CheckBoxInput(String name,String label) {
		super(name,label);
		this.checked = false;
	}
	
	public CheckBoxInput(String name,String label, boolean checked) {
		super(name,label);
		this.checked = checked;
	}
	
	public CheckBoxInput(String name,String label, boolean checked, String cssClass) {
		this(name,label,checked);
		this.cssClass=cssClass;
	}
	
	public CheckBoxInput(String name,String label, boolean checked, String cssClass, String otherHtml) {
		this(name,label,checked,cssClass);
		this.otherHtml=otherHtml;
	}
	
	public boolean isChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}

	@Override
	public String render() {
		String output = this.renderLabel();
		output="<input type=\"checkbox\" name=\""+this.name+"\"";
		
		if(this.checked) {
			output+="checked =\""+this.checked+"\"";
		}
		if(!this.cssClass.isEmpty()) {
			output+="class =\""+this.cssClass+"\"";
		}
		if(!this.otherHtml.isEmpty()) {
			output+=this.otherHtml;
		}
		
		output+=" />\n";
		
		return output;
	}

}
